I want to change the background of a button manually in my WPF app.
I have an image imported into my resources and I want to do:
MyButton.Background = MyProject.Properties.Resources.myImage;
But I get the error:
cannot implicitly convert system.drawing.bitmap to media.brush
How can I do this??
Anonymous User
18-Dec-2013You can create a BitmapImage from a Pack URI to that file.
you have to create an ImageBrush from the BitmapImage to set the Background property.
var uri = new Uri("pack://application:,,,/images/myImage.jpg");var image = new BitmapImage(uri);
MyButton.Background = new ImageBrush(image);